home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / hwclockfirst.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2011-01-25  |  5.0 KB  |  173 lines

  1. #!/bin/sh
  2. # hwclock.sh    Set and adjust the CMOS clock, according to the UTC
  3. #        setting in /etc/default/rcS (see also rcS(5)).
  4. #
  5. # Version:    @(#)hwclock.sh  2.00  14-Dec-1998  miquels@cistron.nl
  6. #
  7. # Patches:
  8. #        2000-01-30 Henrique M. Holschuh <hmh@rcm.org.br>
  9. #         - Minor cosmetic changes in an attempt to help new
  10. #           users notice something IS changing their clocks
  11. #           during startup/shutdown.
  12. #         - Added comments to alert users of hwclock issues
  13. #           and discourage tampering without proper doc reading.
  14.  
  15. # WARNING:    Please read /usr/share/doc/util-linux/README.Debian.hwclock
  16. #        before changing this file. You risk serious clock
  17. #        misbehaviour otherwise.
  18.  
  19. ### BEGIN INIT INFO
  20. # Provides:          hwclockfirst
  21. # Required-Start:    mountdevsubfs
  22. # Required-Stop:
  23. # Default-Start:     S
  24. # X-Start-Before:    checkroot
  25. # Default-Stop:
  26. ### END INIT INFO
  27.  
  28. FIRST=yes    # debian/rules sets this to 'yes' when creating hwclockfirst.sh
  29.  
  30. # Set this to any options you might need to give to hwclock, such
  31. # as machine hardware clock type for Alphas.
  32. HWCLOCKPARS=
  33.  
  34. # Set this to the hardware clock device you want to use, it should
  35. # probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config option.
  36. HCTOSYS_DEVICE=rtc0
  37.  
  38. hwclocksh()
  39. {
  40.     [ ! -x /sbin/hwclock ] && return 0
  41.     [ ! -r /etc/default/rcS ] || . /etc/default/rcS
  42.  
  43.     . /lib/lsb/init-functions
  44.     verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; }
  45.  
  46.     [ "$GMT" = "-u" ] && UTC="yes"
  47.     case "$UTC" in
  48.        no|"")    GMT="--localtime"
  49.         UTC=""
  50.         if [ "X$FIRST" = "Xyes" ] && [ ! -r /etc/localtime ]; then
  51.             if [ -z "$TZ" ]; then
  52.             log_action_msg "System clock was not updated at this time"
  53.             return 1
  54.             fi
  55.         fi
  56.         ;;
  57.        yes)    GMT="--utc"
  58.         UTC="--utc"
  59.         ;;
  60.        *)    log_action_msg "Unknown UTC setting: \"$UTC\""; return 1 ;;
  61.     esac
  62.  
  63.     case "$BADYEAR" in
  64.        no|"")    BADYEAR="" ;;
  65.        yes)    BADYEAR="--badyear" ;;
  66.        *)    log_action_msg "unknown BADYEAR setting: \"$BADYEAR\""; return 1 ;;
  67.     esac
  68.  
  69.     case "$1" in
  70.     start)
  71.         if [ -d /dev/.udev ]; then
  72.         return 0
  73.         fi
  74.  
  75.         if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
  76.         echo "0.0 0 0.0" > /etc/adjtime
  77.         fi
  78.  
  79.         if [ ! -w /etc/adjtime ]; then
  80.         NOADJ="--noadjfile"
  81.         else
  82.             NOADJ=""
  83.         fi
  84.  
  85.         if [ "$FIRST" != yes ]; then
  86.         # Uncomment the hwclock --adjust line below if you want
  87.         # hwclock to try to correct systematic drift errors in the
  88.         # Hardware Clock.
  89.         #
  90.         # WARNING: If you uncomment this option, you must either make
  91.         # sure *nothing* changes the Hardware Clock other than
  92.         # hwclock --systohc, or you must delete /etc/adjtime
  93.         # every time someone else modifies the Hardware Clock.
  94.         #
  95.         # Common "vilains" are: ntp, MS Windows, the BIOS Setup
  96.         # program.
  97.         #
  98.         # WARNING: You must remember to invalidate (delete)
  99.         # /etc/adjtime if you ever need to set the system clock
  100.         # to a very different value and hwclock --adjust is being
  101.         # used.
  102.         #
  103.         # Please read /usr/share/doc/util-linux/README.Debian.hwclock
  104.         # before enabling hwclock --adjust.
  105.  
  106.         #/sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --adjust $GMT $BADYEAR
  107.         :
  108.         fi
  109.  
  110.         if [ "$HWCLOCKACCESS" != no ]; then
  111.         log_action_msg "Setting the system clock"
  112.  
  113.         # Copies Hardware Clock time to System Clock using the correct
  114.         # timezone for hardware clocks in local time, and sets kernel
  115.         # timezone. DO NOT REMOVE.
  116.         if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then
  117.             #    Announce the local time.
  118.             verbose_log_action_msg "System Clock set to: `date $UTC`"
  119.         else
  120.             log_warning_msg "Unable to set System Clock to: `date $UTC`"
  121.         fi
  122.         else
  123.         verbose_log_action_msg "Not setting System Clock"
  124.         fi
  125.         ;;
  126.     stop|restart|reload|force-reload)
  127.         #
  128.         # Updates the Hardware Clock with the System Clock time.
  129.         # This will *override* any changes made to the Hardware Clock.
  130.         #
  131.         # WARNING: If you disable this, any changes to the system
  132.         #          clock will not be carried across reboots.
  133.         #
  134.         if [ ! -w /etc/adjtime ]; then
  135.         NOADJ="--noadjfile"
  136.         else
  137.             NOADJ=""
  138.         fi
  139.  
  140.         if [ "$HWCLOCKACCESS" != no ]; then
  141.         log_action_msg "Saving the system clock"
  142.         if [ "$GMT" = "-u" ]; then
  143.             GMT="--utc"
  144.         fi
  145.         if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then
  146.             verbose_log_action_msg "Hardware Clock updated to `date`"
  147.         fi
  148.         else
  149.         verbose_log_action_msg "Not saving System Clock"
  150.         fi
  151.         ;;
  152.     show)
  153.         if [ ! -w /etc/adjtime ]; then
  154.         NOADJ="--noadjfile"
  155.         else
  156.             NOADJ=""
  157.         fi
  158.  
  159.         if [ "$HWCLOCKACCESS" != no ]; then
  160.         /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show $GMT $HWCLOCKPARS $BADYEAR $NOADJ
  161.         fi
  162.         ;;
  163.     *)
  164.         log_success_msg "Usage: hwclock.sh {start|stop|reload|force-reload|show}"
  165.         log_success_msg "       start sets kernel (system) clock from hardware (RTC) clock"
  166.         log_success_msg "       stop and reload set hardware (RTC) clock from kernel (system) clock"
  167.         return 1
  168.         ;;
  169.     esac
  170. }
  171.  
  172. hwclocksh "$@"
  173.